package com.efuture.mutlithread;

/**
 * @ClassNAME ThreadPriority
 * @Description 线程的优先级 默认为5 最低为1 最高为10
 * @Author zhaoshanshan
 * @Date 2021/9/11 9:57 上午
 * @Version 1.0
 */
public class ThreadPriority {

    public static void main(String[] args) {
        //获取当前的线程对象
        Thread mainThread = Thread.currentThread();
        //获取当前线程的优先级
        System.out.println(mainThread.getName()+"的优先级:"+mainThread.getPriority()); //默认为5
        ThreadPriorityTest t = new ThreadPriorityTest();
        t.start();
        //获取当前线程的优先级
        System.out.println(t.getName()+"的优先级:"+t.getPriority()); //默认为5
        //设置线程的优先级
        mainThread.setPriority(1);//设置主线程优先级为最低1
        t.setPriority(10);//设置子线程优先级为最高 10
        //重新获取设置后的线程优先级
        System.out.println(mainThread.getName()+"的优先级:"+mainThread.getPriority());
        System.out.println(t.getName()+"的优先级:"+t.getPriority());
    }
}
class ThreadPriorityTest extends Thread{
    @Override
    public void run() {

    }
}